//
//  MyCell.m
//  Test
//
//  Created by 祝文博 on 15/3/4.
//  Copyright (c) 2015年 KevinLab. All rights reserved.
//

#import "MyCell.h"
#import "UIImageView+WebCache.h"

#define CELL_HEIGHT 80;

@interface MyCell()

@property (nonatomic, strong) UIImageView *thumbImageView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *addressLabel;

@end

@implementation MyCell

+ (CGFloat)cellHeight
{
    return CELL_HEIGHT;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    if (self) {
        self.thumbImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 80, 60)];
        self.thumbImageView.contentMode = UIViewContentModeScaleAspectFill;
        self.thumbImageView.image = [UIImage imageNamed:@"tab_icon_1"];
        [self.contentView addSubview:self.thumbImageView];
        
        self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.thumbImageView.frame) + 10,
                                                                   10,
                                                                   WINDOW_WIDTH - 20 - self.thumbImageView.frame.size.width,
                                                                   20)];
        self.nameLabel.backgroundColor = [UIColor clearColor];
        self.nameLabel.textColor = [UIColor grayColor];
        self.nameLabel.text = @"a";
        [self.contentView addSubview:self.nameLabel];
        
        self.addressLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.nameLabel.frame.origin.x,
                                                                      CGRectGetMaxY(self.nameLabel.frame) + 15,
                                                                      WINDOW_WIDTH - 20 - self.thumbImageView.frame.size.width,
                                                                      20)];
        self.addressLabel.backgroundColor = [UIColor clearColor];
        self.addressLabel.textColor = [UIColor grayColor];
        self.addressLabel.text = @"b";
        [self.contentView addSubview:self.addressLabel];
    }
    
    return self;
}

- (void) setName:(NSString *) name
{
    _name = name;
    self.nameLabel.text = name;
}

- (void) setAddress:(NSString *)address
{
    _address = address;
    self.addressLabel.text = address;
}

- (void) setImageUrl:(NSURL *)imageUrl
{
    _imageUrl = imageUrl;
    [self.thumbImageView sd_setImageWithURL:imageUrl placeholderImage:[UIImage imageNamed:@"Loading"]];
}

@end
